library(tidyverse)

DATA <- tribble(
  ~GROUP                , ~PE , ~CILO, ~CIHI,
  "Joe Biden\nvoters"   , 59.8,  58.7,  60.8,
  "Donald Trump\nvoters", 84.7,  84.0,  85.4,
  "Other\nvoters"       , 62.1,  58.4,  65.9)

DATA$GROUP <- factor(DATA$GROUP, levels=c("Joe Biden\nvoters", "Donald Trump\nvoters", "Other\nvoters"))

ggplot(data=DATA, aes(x=GROUP, y=PE, fill=GROUP)) +
  geom_col(size=1.1, color="black", width=0.85) + 
  geom_errorbar(aes(ymin=CILO, ymax=CIHI), width=0.25) +
  geom_text(aes(x=GROUP, y=CIHI+5, label=sprintf("%0.1f", PE)), size=5.5) +
  scale_fill_manual(values=c("Joe Biden\nvoters"="green3", "Donald Trump\nvoters"="green3", "Other\nvoters"="green3")) +
  scale_y_continuous(limits=c(0,100), breaks=seq(0,100,10), expand=c(0,0), name="%") +
  labs(title="Mean rating about police", subtitle="on a 0-to-100 scale", caption="Data source: American National Election Studies 2020 Time Series Study.\nPlot by [your name here].") +
  theme(
    axis.text.x        = element_text(size=15, color="black", margin=margin(t=7, b=7)),
    axis.text.y        = element_text(size=15, color="black", margin=margin(r=7)),
    axis.ticks.x       = element_blank(),
    axis.ticks.y       = element_blank(),
    axis.title.x       = element_blank(),
    axis.title.y       = element_text(size=15, color="black", angle=0, vjust=0.5),
    legend.position    = "none",
    panel.background   = element_rect(fill="gray80"),
    panel.border       = element_rect(size=2, color="black", fill=NA),
    panel.grid.major.x = element_blank(),
    panel.grid.major.y = element_line(size=0.25, color="gray60"), 
    panel.grid.minor.x = element_blank(),
    panel.grid.minor.y = element_blank(),
    plot.caption       = element_text(size=12, hjust=0.5, margin=margin(t=7)),
    plot.margin        = unit(c(t=0.5, r=0.5, b=0.5, l=0.5), "cm"),
    plot.subtitle      = element_text(size=18,              hjust=0.5, margin=margin(t=0, b=10)),
    plot.title         = element_text(size=20, face="bold", hjust=0.5, margin=margin(t=0, b=5)))

ggsave(file="Plot 1.wmf", width=6.5, height=6)
